﻿namespace Snipps.Core.Entities
{
    using System;
    using System.Collections.Generic;

    public class Snippet : EntityBase, IEquatable<Snippet>
    {
        public Snippet()
        {
            Tags = new List<Tag>();
        }

        public string Name { get; set; }

        public string Content { get; set; }

        public ProgrammingLang ProgrammingLang { get; set; }

        public IList<Tag> Tags { get; set; }

        public bool Equals(Snippet other)
        {
            if (other == null)
            {
                return false;
            }

            if (ProgrammingLang != null)
            {
                if (!ProgrammingLang.Equals(other.ProgrammingLang))
                {
                    return false;
                }
            }
            else if (other.ProgrammingLang != null)
            {
                return false;
            }

            return string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase);
        }

        public override int GetHashCode()
        {
            return 1;
        }

        public static bool operator ==(Snippet left, Snippet right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(Snippet left, Snippet right)
        {
            return !Equals(left, right);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(obj, this))
            {
                return true;
            }

            return Equals(obj as Snippet);
        }
    }
}